#ifndef SINGLE_GROUP_H
#define SINGLE_GROUP_H

#include <map>
#include <string>
#include <windows.h>
#include "asgka_common.h"

class singleMember;
class asgkaCenter;

class singleGroup
{
public:
	singleGroup();
	singleGroup(const std::string &name, singleMember *leader);
	~singleGroup();

	void setName(const std::string &name);
	void setLeader(singleMember *leader);
	int setGroupKeyA(c_asgka_element content);
	int setGroupKeyR(c_asgka_element content);
	int setCiphertext1(c_asgka_element content);
	int setCiphertext2(c_asgka_element content);
	int setCiphertext3(c_asgka_element content);
	int setDecryptKey(c_asgka_element content);
	int setPlaintext(c_asgka_element content);
	int setPubH(c_asgka_element content);
	int setPriR(c_asgka_element content);
	int setPriX(c_asgka_element content);

	long getGroupID() const;
	int getGroupPopulation() const;
	std::string getGroupName() const;
	singleMember *getGroupLeader() const;
	bool isAMember(const std::string &name) const;

	c_asgka_element getAddrofGroupKeyA() const;
	c_asgka_element getAddrofGroupKeyR() const;
	c_asgka_element getAddrofDecryptKey() const;
	c_asgka_element getAddrofPlaintext() const;
	c_asgka_element getAddrofCiphertext1() const;
	c_asgka_element getAddrofCiphertext2() const;
	c_asgka_element getAddrofCiphertext3() const;
	c_asgka_element getAddrofPubH() const;
	c_asgka_element getAddrofPriR() const;
	c_asgka_element getAddrofPriX() const;
	const std::map<std::string, singleMember *> *getAddrofMemberlist() const;
	singleMember *getMemberByName(const std::string &name) const;
	void generateMemberList(std::map<std::string, u_long> &member_list) const;
	
	int sendMessagetoGroup(const char *buf, int length) const;
	int decryptMessage(char *plainbuf, const char *ciphertext, int length) const;

	void addAMember(singleMember *member);
	void deleteAMember(const std::string &name);

	bool isAllXigamaOK();
	bool isAllHOK();
	bool isCipherTextOK();
	bool isAllROK();
	bool isAllAOK();

private:
	long m_id;

	singleMember *m_leader;
	std::string m_name;

	// Elements a group keep
	asgka_element m_my_pubH;
	asgka_element m_my_priR;
	asgka_element m_my_priX;
	asgka_element m_my_groupKeyA;
	asgka_element m_my_groupKeyR;
	asgka_element m_ciphertext1;
	asgka_element m_ciphertext2;
	asgka_element m_ciphertext3;
	asgka_element m_my_decrypt_key;
	asgka_element m_key;

	std::map<std::string, singleMember *> m_member_list;
};

#endif

